﻿using Autofac;
using System.Linq;
using System.Reflection;

namespace DTM.WinApp.Bootstrapper
{
    public class RegistrationModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var assemblies = Assembly.GetExecutingAssembly();

            builder.RegisterAssemblyTypes(assemblies)
               .Where(t => t.Name.EndsWith("Form"))
               .AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(assemblies)
               .Where(t => t.Name.EndsWith("Presenter"))
               .AsImplementedInterfaces();

            builder.RegisterType<ApplicationManager>()
                .As<IApplicationManager>()
                .SingleInstance();
        }
    }
}